﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace OracleDAL.ResourceManage
{
    public class querybuilder
    {
        public DataSet getResInfo(string belongSystem)
        {
            DataSet ds = new DataSet();
            string strSql = "select RESID,NETWORKID,QUERYFROMVIEW,MODIFYINFOTABLE,VIEWINFO,ISRAGATORY,ISADDITIVE,ISEDITABLE,NEEDAUTOCODE,JUDGEUNIQUE,HOTKEY,ICON,REMARK,ISDELETE,ISORDER,ISROWNUM";
            if (string.IsNullOrEmpty(belongSystem))
            {
                strSql += " from cfg_resource_info";
            }
            else
            {
                strSql += " from cfg_resource_info where NETWORKID='" + belongSystem.ToUpper() + "'";
              
            }
            ds = DBUtility.OracleHelper.Query(strSql);
            return ds;
        }
        public DataSet getResField(string tableName)
        {
            DataSet ds = new DataSet();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select TABLENAME,ENFIELD,CHFIELD,ISKEY,DATATYPE,ISNULL,ISVISIBLE,ISEDITABLE,ISADDITIVE,ISRAGATORY,ISSTATISTIC,SERIAL,GETRULE,");
            strSql.Append("ISADDITIVEINTO,ISEDITABLEINTO,CODEINPUTINTO,CHANGESETNULL,CUSTOMSELECT,TREEBRANCHTYPES,TREEROOTRESID,REMARK,ISTRANSITION,TRANSTABLE,");
            strSql.Append("TRANSCOL,TRANSEDCOL,VALUETYPE,ISAUTOCODE,PUBLICVISIBLE,ISAOTOSELECT");

            if (string.IsNullOrEmpty(tableName))
            {
                strSql.Append(" from cfg_resource_fields order by tablename");
            }
            else 
            {
                strSql.Append(" from cfg_resource_fields  where tablename='" + tableName.ToUpper() + "' order by SERIAL");
            }
            ds = DBUtility.OracleHelper.Query(strSql.ToString());
            return ds;
        }
        public DataSet getDetail(string strSql)
        {
            return DBUtility.OracleHelper.Query(strSql);
        }
        public DataSet getBelongSystem()
        {
            string sqlStr = "select distinct b.systemname,cfg.networkid from cfg_resource_info cfg,belongsystem b where cfg.networkid=b.id";
            return DBUtility.OracleHelper.Query(sqlStr);
        }
        public DataSet getResource()
        {
            string sqlStr = "select  distinct resid,viewinfo from cfg_resource_info";
            return DBUtility.OracleHelper.Query(sqlStr);

        }
    }
}
